package cn.gary.oaserver.service.impl;


import cn.gary.oaserver.entity.TEmployee;
import cn.gary.oaserver.mapper.TEmployeeMapper;
import cn.gary.oaserver.params.Result;
import cn.gary.oaserver.service.ITEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gary
 * @since 2024-03-15
 */
@Service
public class TEmployeeServiceImpl extends ServiceImpl<TEmployeeMapper, TEmployee> implements ITEmployeeService {


    @Override
    public IPage<TEmployee> getEmpByQuery(Page<TEmployee> pageInfo, String empName, Integer politicsId, Integer deptId, String beginTime, String endTime, String sort) {
        return baseMapper.getEmpByQuery ( pageInfo, empName, politicsId, deptId, beginTime, endTime, sort );
    }

    @Override
    public Result maxWorkID() {
        List<Map<String, Object>> maps = baseMapper.selectMaps(new QueryWrapper<TEmployee>().select("max(workID)"));
        String workID = String.format("%08d", Integer.parseInt(maps.get(0).get("max(workID)").toString()) + 1);
        return Result.success(null, workID);
     }

    @Override
    public Result insertEmp(TEmployee employee) {
        return this.save ( employee ) ?
                Result.success ("添加成功" ) :
                Result.error ( "添加失败" );
    }

    @Override
    public Result updateEmp(TEmployee employee) {
        return this.updateById ( employee ) ?
                Result.success ("修改成功" ) :
                Result.error ( "修改失败" );
    }

    @Override
    public Result delEmp(Integer id) {
        return this.removeById ( id ) ?
                Result.success ( "删除成功" ) :
                Result.error ( "删除失败" );
    }
}
